import request from '@/utils/request'
import { API_CONFIG } from '@/config'
import type { DeviceMenu,MapDeviceMark } from '@/types'

// 设备管理-根据目录分页查询设备
export function $getDeviceList(id: string,isGetALL:boolean = false) {
  return request.get(API_CONFIG.ENDPOINTS.DEVICE.ListByMenuID(id,isGetALL))
}

// 设备管理-获取所有已经在地图标记的设备
export function $getAllDeviceInMap() {
  return request.get(API_CONFIG.ENDPOINTS.DEVICE.ALL_DEVICE_IN_MAP)
}

// 设备管理-分页查询设备列表
export function getDeviceListByPage(params: {
  page: number
  pageSize: number
  keyWord?: string
  menuId: number
  isContainsSubMenu?: boolean
}) {
  return request.post('/deviceController/getDeviceListByPage', params)
}

// 获取所有菜单
export function getAllMenu() {
  return request.get(API_CONFIG.ENDPOINTS.Device_Menu.ALL_MENU)
}

// 获取所有菜单带设备数量
export function getAllMenuCount() {
  return request.get(API_CONFIG.ENDPOINTS.Device_Menu.ALL_MENU_COUNT)
}
/**
 * 创建设备目录
 */
export function createMenu(data: Partial<DeviceMenu>) {
  return request.post<DeviceMenu>('/menuController/addMenu', data)
}

/**
 * 更新菜单
 */
export function updateMenuName(id: number, name: string) {
  return request.put(`/menuController/updateMenuName?id=${id}&menuName=${name}`)
}

/**
 * 删除菜单
 */
export function deleteMenu(id: number) {
  return request.delete(`/menuController/deleteMenu?id=${id}`)
}


/**
 * 移动摄像机到分组
 */
export function moveCamerasToGroup(cameraIds: number[], groupId: number) {
  return request.post(`menuController/updateDeviceMenu?id=${groupId}`, cameraIds)
}


// 修改设备名字
export function updateDeviceName(id: number, name: string) {
  return request.get(`/deviceController/setCameraName?id=${id}&name=${name}`)
}

// 在地图上标记设备
export function markDeviceOnMap(data: MapDeviceMark) {
  return request.post(`/deviceController/setCameraInMap`,data)
}


// 根据名称关键字搜索设备
export function $getDeviceListByKeyword(keyword: string) {
  return request.get(`/deviceController/getAllDeviceListByName?keyName=${keyword}`)
}

// 导出
export function $exportDeviceList() {
  return request.post(`/deviceController/exportDeviceInfos`)
}

// 导入设备
export function $importDevices(file: File) {
  const formData = new FormData()
  formData.append('file', file)
  return request.post('/deviceController/restoreDevices', formData)
}

// 批量删除设备
export function $deleteDevices(cameraIds: number[]) {
  return request.deleteData(`/deviceController/patchDelete`, { data: cameraIds })
} 